using System;
using Oracle.ManagedDataAccess.Client;
using OracleInternal.Common;

namespace OracleInternal.TTC
{
	internal class TTCFetch : TTCFunction
	{
		internal TTCFetch(MarshallingEngine mEngine)
			: base(mEngine, 5, 0)
		{
		}

		internal void WriteMessage(int cursorId, int noOfRowsToFetch)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCFetch, OracleTraceFuncName.WriteMessage);
			}
			try
			{
				WriteFunctionHeader();
				m_marshallingEngine.MarshalSWORD(cursorId);
				m_marshallingEngine.MarshalSWORD(noOfRowsToFetch);
				m_marshallingEngine.m_oraBufWriter.FlushData();
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCFetch, OracleTraceFuncName.WriteMessage, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCFetch, OracleTraceFuncName.WriteMessage);
				}
			}
		}
	}
}
